package com.spzx.channel.configure;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * ClassName: ThreadPoolConfig
 * Package: com.spzx.channel.configure
 * Description:
 */
@Configuration
public class ThreadPoolConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor (){
        int processorsCount = Runtime.getRuntime().availableProcessors();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                processorsCount * 2,
                processorsCount * 2,
                1,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(200),
                Executors.defaultThreadFactory(),
                (runnable, executor) -> {
                    executor.submit(runnable);
                });
        threadPoolExecutor.prestartAllCoreThreads();
        return threadPoolExecutor;
    }

}
